package com.boang.dead;

public class DeadLock {
    private static final Object lock1 = new Object();
    private static final Object lock2 = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (lock1) {
                System.out.println("t1: holding lock1...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1: Waiting for lock2...");
                synchronized (lock2) {
                    System.out.println("t1: holding lock1 and lock2...");
                }
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (lock2) {
                System.out.println("t2: holding lock2...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2: waiting for lock1...");
                synchronized (lock1) {
                    System.out.println("t2: holding lock2 and lock1");
                }
            }
        });

        t1.start();
        t2.start();
    }
}